package com.google.code.twithis.fourfive.ui;

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.component.BitmapField;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.HorizontalFieldManager;

import com.google.code.twithis.fourfive.ui.component.BaseScreen;

public abstract class StepScreen extends BaseScreen {

	private BitmapField bitmapField;

	public StepScreen(long style) {
		super(style);

		buildHeader();
	}

	protected int getStepHeight() {
		return 55;
	}

	public abstract String getImage();

	public abstract String getHeaderTitle();

	private void buildHeader() {
		final LabelField field = new LabelField(getHeaderTitle(), Field.FIELD_VCENTER);

		HorizontalFieldManager m = new HorizontalFieldManager(Field.USE_ALL_WIDTH) {

			protected void sublayout(int width, int height) {
				System.out.println(height);

				height = getStepHeight();

				setPositionChild(bitmapField, 10, 10);
				this.layoutChild(bitmapField, width, height);

				setPositionChild(field, 50, 15);
				this.layoutChild(field, width, height);

				// super.sublayout(width, height);
				setExtent(width, height);
			}

			protected void paintBackground(Graphics g) {
				g.setBackgroundColor(0x00EFEFEF);
				g.clear();
			}
		};

		bitmapField = new BitmapField(Bitmap.getBitmapResource(getImage()), Field.FIELD_VCENTER);

		Font font = Font.getDefault().derive(Font.BOLD, 26);

		field.setFont(font);

		m.add(bitmapField);
		m.add(field);

		this.add(m);
	}

}
